package com.liner;

import java.util.Arrays;

/**
 * @author 一条淡水鱼 ゆ
 * @Classname InsertionSort
 * @Description 插入排序
 * @Date 2023-04-01
 */
public class InsertionSort {
    public static void main(String[] args) {
        int[] array = BubbleSort.getInts();
        System.out.println(Arrays.toString(array));

        sort(array);

        System.out.println(Arrays.toString(array));


    }

    private static void sort(int[] array) {
        for (int i = 1; i < array.length; i++) {
            int j = i;
            while (j> 0){
                if (array[j] < array[j-1]) {
                    int temp = array[j];
                    array[j] = array[j-1];
                    array[j-1] = temp;
                    j--;
                }else{
                    break;
                }
            }

        }
    }
}
